﻿///////////////////////////////////////////////////////////////
// This is generated code. 
//////////////////////////////////////////////////////////////
// Code is generated using LLBLGen Pro version: 2.5
// Code is generated on: Thursday, October 16, 2008 1:31:24 PM
// Code is generated using templates: SD.TemplateBindings.SharedTemplates.NET20
// Templates vendor: Solutions Design.
// Templates version: 
//////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using NL.ADA.ConfigService.DAL.EntityClasses;
using NL.ADA.ConfigService.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;

namespace NL.ADA.ConfigService.DAL.FactoryClasses
{
	
	// __LLBLGENPRO_USER_CODE_REGION_START AdditionalNamespaces
	// __LLBLGENPRO_USER_CODE_REGION_END
	
	
	/// <summary>general base class for the generated factories</summary>
	[Serializable]
	public partial class EntityFactoryBase2 : EntityFactoryCore2
	{
		private string _entityName;
		private NL.ADA.ConfigService.DAL.EntityType _typeOfEntity;
		
		/// <summary>CTor</summary>
		/// <param name="entityName">Name of the entity.</param>
		/// <param name="typeOfEntity">The type of entity.</param>
		public EntityFactoryBase2(string entityName, NL.ADA.ConfigService.DAL.EntityType typeOfEntity)
		{
			_entityName = entityName;
			_typeOfEntity = typeOfEntity;
		}
		
		/// <summary>Creates, using the generated EntityFieldsFactory, the IEntityFields2 object for the entity to create.</summary>
		/// <returns>Empty IEntityFields2 object.</returns>
		public override IEntityFields2 CreateFields()
		{
			return EntityFieldsFactory.CreateEntityFieldsObject(_typeOfEntity);
		}
		
		/// <summary>Creates a new entity instance using the GeneralEntityFactory in the generated code, using the passed in entitytype value</summary>
		/// <param name="entityTypeValue">The entity type value of the entity to create an instance for.</param>
		/// <returns>new IEntity instance</returns>
		public override IEntity2 CreateEntityFromEntityTypeValue(int entityTypeValue)
		{
			return GeneralEntityFactory.Create((EntityType)entityTypeValue);
		}

		/// <summary>Creates the relations collection to the entity to join all targets so this entity can be fetched. </summary>
		/// <returns>null if the entity isn't in a hierarchy of type TargetPerEntity, otherwise the relations collection needed to join all targets together to fetch all subtypes of this entity and this entity itself</returns>
		public override IRelationCollection CreateHierarchyRelations() 
		{
			return InheritanceInfoProviderSingleton.GetInstance().GetHierarchyRelations(_entityName);
		}

		/// <summary>This method retrieves, using the InheritanceInfoprovider, the factory for the entity represented by the values passed in.</summary>
		/// <param name="fieldValues">Field values read from the db, to determine which factory to return, based on the field values passed in.</param>
		/// <param name="entityFieldStartIndexesPerEntity">indexes into values where per entity type their own fields start.</param>
		/// <returns>the factory for the entity which is represented by the values passed in.</returns>
		public override IEntityFactory2 GetEntityFactory(object[] fieldValues, Dictionary<string, int> entityFieldStartIndexesPerEntity) 
		{
			IEntityFactory2 toReturn = (IEntityFactory2)InheritanceInfoProviderSingleton.GetInstance().GetEntityFactory(_entityName, fieldValues, entityFieldStartIndexesPerEntity);
			if(toReturn == null)
			{
				toReturn = this;
			}
			return toReturn;
		}
		
		/// <summary>Gets a predicateexpression which filters on the entity with type belonging to this factory.</summary>
		/// <param name="negate">Flag to produce a NOT filter, (true), or a normal filter (false). </param>
		/// <returns>ready to use predicateexpression, or an empty predicate expression if the belonging entity isn't a hierarchical type.</returns>
		public override IPredicateExpression GetEntityTypeFilter(bool negate) 
		{
			return InheritanceInfoProviderSingleton.GetInstance().GetEntityTypeFilter(this.ForEntityName, negate);
		}
				
		/// <summary>returns the name of the entity this factory is for, e.g. "EmployeeEntity"</summary>
		public override string ForEntityName 
		{ 
			get { return _entityName; }
		}
	}
	
	/// <summary>Factory to create new, empty ApplicationEntity objects.</summary>
	[Serializable]
	public partial class ApplicationEntityFactory : EntityFactoryBase2 {
		/// <summary>CTor</summary>
		public ApplicationEntityFactory() : base("ApplicationEntity", NL.ADA.ConfigService.DAL.EntityType.ApplicationEntity) { }

		/// <summary>Creates a new, empty ApplicationEntity object.</summary>
		/// <returns>A new, empty ApplicationEntity object.</returns>
		public override IEntity2 Create() {
			IEntity2 toReturn = new ApplicationEntity();
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewApplication
			// __LLBLGENPRO_USER_CODE_REGION_END
			
			return toReturn;
		}
		
		/// <summary>Creates a new ApplicationEntity instance but uses a special constructor which will set the Fields object of the new IEntity2 instance to the passed in fields object.</summary>
		/// <param name="fields">Populated IEntityFields2 object for the new IEntity2 to create</param>
		/// <returns>Fully created and populated (due to the IEntityFields2 object) IEntity2 object</returns>
		public override IEntity2 Create(IEntityFields2 fields) {
			IEntity2 toReturn = new ApplicationEntity(fields);
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewApplicationUsingFields
			// __LLBLGENPRO_USER_CODE_REGION_END
			
			return toReturn;
		}

		#region Included Code

		#endregion
	}	
	/// <summary>Factory to create new, empty ApplicationModeModifiedEntity objects.</summary>
	[Serializable]
	public partial class ApplicationModeModifiedEntityFactory : EntityFactoryBase2 {
		/// <summary>CTor</summary>
		public ApplicationModeModifiedEntityFactory() : base("ApplicationModeModifiedEntity", NL.ADA.ConfigService.DAL.EntityType.ApplicationModeModifiedEntity) { }

		/// <summary>Creates a new, empty ApplicationModeModifiedEntity object.</summary>
		/// <returns>A new, empty ApplicationModeModifiedEntity object.</returns>
		public override IEntity2 Create() {
			IEntity2 toReturn = new ApplicationModeModifiedEntity();
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewApplicationModeModified
			// __LLBLGENPRO_USER_CODE_REGION_END
			
			return toReturn;
		}
		
		/// <summary>Creates a new ApplicationModeModifiedEntity instance but uses a special constructor which will set the Fields object of the new IEntity2 instance to the passed in fields object.</summary>
		/// <param name="fields">Populated IEntityFields2 object for the new IEntity2 to create</param>
		/// <returns>Fully created and populated (due to the IEntityFields2 object) IEntity2 object</returns>
		public override IEntity2 Create(IEntityFields2 fields) {
			IEntity2 toReturn = new ApplicationModeModifiedEntity(fields);
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewApplicationModeModifiedUsingFields
			// __LLBLGENPRO_USER_CODE_REGION_END
			
			return toReturn;
		}

		#region Included Code

		#endregion
	}	
	/// <summary>Factory to create new, empty ConfigEntity objects.</summary>
	[Serializable]
	public partial class ConfigEntityFactory : EntityFactoryBase2 {
		/// <summary>CTor</summary>
		public ConfigEntityFactory() : base("ConfigEntity", NL.ADA.ConfigService.DAL.EntityType.ConfigEntity) { }

		/// <summary>Creates a new, empty ConfigEntity object.</summary>
		/// <returns>A new, empty ConfigEntity object.</returns>
		public override IEntity2 Create() {
			IEntity2 toReturn = new ConfigEntity();
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewConfig
			// __LLBLGENPRO_USER_CODE_REGION_END
			
			return toReturn;
		}
		
		/// <summary>Creates a new ConfigEntity instance but uses a special constructor which will set the Fields object of the new IEntity2 instance to the passed in fields object.</summary>
		/// <param name="fields">Populated IEntityFields2 object for the new IEntity2 to create</param>
		/// <returns>Fully created and populated (due to the IEntityFields2 object) IEntity2 object</returns>
		public override IEntity2 Create(IEntityFields2 fields) {
			IEntity2 toReturn = new ConfigEntity(fields);
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewConfigUsingFields
			// __LLBLGENPRO_USER_CODE_REGION_END
			
			return toReturn;
		}

		#region Included Code

		#endregion
	}	
	/// <summary>Factory to create new, empty ConfigTypeEntity objects.</summary>
	[Serializable]
	public partial class ConfigTypeEntityFactory : EntityFactoryBase2 {
		/// <summary>CTor</summary>
		public ConfigTypeEntityFactory() : base("ConfigTypeEntity", NL.ADA.ConfigService.DAL.EntityType.ConfigTypeEntity) { }

		/// <summary>Creates a new, empty ConfigTypeEntity object.</summary>
		/// <returns>A new, empty ConfigTypeEntity object.</returns>
		public override IEntity2 Create() {
			IEntity2 toReturn = new ConfigTypeEntity();
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewConfigType
			// __LLBLGENPRO_USER_CODE_REGION_END
			
			return toReturn;
		}
		
		/// <summary>Creates a new ConfigTypeEntity instance but uses a special constructor which will set the Fields object of the new IEntity2 instance to the passed in fields object.</summary>
		/// <param name="fields">Populated IEntityFields2 object for the new IEntity2 to create</param>
		/// <returns>Fully created and populated (due to the IEntityFields2 object) IEntity2 object</returns>
		public override IEntity2 Create(IEntityFields2 fields) {
			IEntity2 toReturn = new ConfigTypeEntity(fields);
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewConfigTypeUsingFields
			// __LLBLGENPRO_USER_CODE_REGION_END
			
			return toReturn;
		}

		#region Included Code

		#endregion
	}	
	/// <summary>Factory to create new, empty ModeEntity objects.</summary>
	[Serializable]
	public partial class ModeEntityFactory : EntityFactoryBase2 {
		/// <summary>CTor</summary>
		public ModeEntityFactory() : base("ModeEntity", NL.ADA.ConfigService.DAL.EntityType.ModeEntity) { }

		/// <summary>Creates a new, empty ModeEntity object.</summary>
		/// <returns>A new, empty ModeEntity object.</returns>
		public override IEntity2 Create() {
			IEntity2 toReturn = new ModeEntity();
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewMode
			// __LLBLGENPRO_USER_CODE_REGION_END
			
			return toReturn;
		}
		
		/// <summary>Creates a new ModeEntity instance but uses a special constructor which will set the Fields object of the new IEntity2 instance to the passed in fields object.</summary>
		/// <param name="fields">Populated IEntityFields2 object for the new IEntity2 to create</param>
		/// <returns>Fully created and populated (due to the IEntityFields2 object) IEntity2 object</returns>
		public override IEntity2 Create(IEntityFields2 fields) {
			IEntity2 toReturn = new ModeEntity(fields);
			
			// __LLBLGENPRO_USER_CODE_REGION_START CreateNewModeUsingFields
			// __LLBLGENPRO_USER_CODE_REGION_END
			
			return toReturn;
		}

		#region Included Code

		#endregion
	}

	/// <summary>Factory to create new, empty Entity objects based on the entity type specified. Uses  entity specific factory objects</summary>
	[Serializable]
	public partial class GeneralEntityFactory
	{
		/// <summary>Creates a new, empty Entity object of the type specified</summary>
		/// <param name="entityTypeToCreate">The entity type to create.</param>
		/// <returns>A new, empty Entity object.</returns>
		public static IEntity2 Create(EntityType entityTypeToCreate)
		{
			IEntityFactory2 factoryToUse = null;
			switch(entityTypeToCreate)
			{
				case NL.ADA.ConfigService.DAL.EntityType.ApplicationEntity:
					factoryToUse = new ApplicationEntityFactory();
					break;
				case NL.ADA.ConfigService.DAL.EntityType.ApplicationModeModifiedEntity:
					factoryToUse = new ApplicationModeModifiedEntityFactory();
					break;
				case NL.ADA.ConfigService.DAL.EntityType.ConfigEntity:
					factoryToUse = new ConfigEntityFactory();
					break;
				case NL.ADA.ConfigService.DAL.EntityType.ConfigTypeEntity:
					factoryToUse = new ConfigTypeEntityFactory();
					break;
				case NL.ADA.ConfigService.DAL.EntityType.ModeEntity:
					factoryToUse = new ModeEntityFactory();
					break;
			}
			return factoryToUse.Create();
		}		
	}
}
